home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr54 / bison118.zip / GETARGS.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  3KB  |  135 lines

  1. /* Parse command line arguments for bison,
  2.    Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of Bison, the GNU Compiler Compiler.
  5.  
  6. Bison is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Bison is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Bison; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "getopt.h"
  23. #include "system.h"
  24. #include "files.h"
  25.  
  26. int verboseflag;
  27. int definesflag;
  28. int debugflag;
  29. int nolinesflag;
  30. char *spec_name_prefix; /* for -p.  */
  31. char *spec_file_prefix; /* for -b. */
  32. extern int fixed_outfiles;/* for -y */
  33.  
  34. extern void fatal();
  35.  
  36. struct option longopts[] =
  37. {
  38.   {"debug", 0, &debugflag, 1},
  39.   {"defines", 0, &definesflag, 1},
  40.   {"file-prefix", 1, 0, 'b'},
  41.   {"fixed-output-files", 0, &fixed_outfiles, 1},
  42.   {"name-prefix", 1, 0, 'a'},
  43.   {"no-lines", 0, &nolinesflag, 1},
  44.   {"output-file", 1, 0, 'o'},
  45.   {"verbose", 0, &verboseflag, 1},
  46.   {"version", 0, 0, 'V'},
  47.   {"yacc", 0, &fixed_outfiles, 1},
  48.   {0, 0, 0, 0}
  49. };
  50.  
  51. void
  52. getargs(argc, argv)
  53.      int argc;
  54.      char *argv[];
  55. {
  56.   register int c;
  57.   int longind;
  58.   extern char *program_name;
  59.   extern char *version_string;
  60.  
  61.   verboseflag = 0;
  62.   definesflag = 0;
  63.   debugflag = 0;
  64.   fixed_outfiles = 0;
  65.  
  66.   while ((c = getopt_long (argc, argv, "yvdltVo:b:p:", longopts, &longind))
  67.      != EOF)
  68.     {
  69.       if (c == 0 && longopts[longind].flag == 0)
  70.     c = longopts[longind].val;
  71.       switch (c)
  72.     {
  73.     case 0:
  74.       /* Certain long options cause getopt_long to return 0.  */
  75.       break;
  76.  
  77.     case 'y':
  78.       fixed_outfiles = 1;
  79.       break;
  80.       
  81.     case 'V':
  82.       printf("%s", version_string);
  83.       break;
  84.       
  85.     case 'v':
  86.       verboseflag = 1;
  87.       break;
  88.       
  89.     case 'd':
  90.       definesflag = 1;
  91.       break;
  92.       
  93.     case 'l':
  94.       nolinesflag = 1;
  95.       break;
  96.       
  97.     case 't':
  98.       debugflag = 1;
  99.       break;
  100.       
  101.     case 'o':
  102.       spec_outfile = optarg;
  103.       break;
  104.       
  105.     case 'b':
  106.       spec_file_prefix = optarg;
  107.       break;
  108.       
  109.     case 'p':
  110.       spec_name_prefix = optarg;
  111.       break;
  112.       
  113.     default:
  114.       fprintf (stderr, "\
  115. Usage: %s [-dltvyV] [-b file-prefix] [-o outfile] [-p name-prefix]\n\
  116.        [--debug] [--defines] [--fixed-output-files] [--no-lines]\n\
  117.        [--verbose] [--version] [--yacc]\n\
  118.        [--file-prefix=prefix] [--name-prefix=prefix]\n\
  119.        [--output-file=outfile] grammar-file\n",
  120.            program_name);
  121.       exit (1);
  122.     }
  123.     }
  124.  
  125.   if (optind == argc)
  126.     {
  127.       fprintf(stderr, "%s: no grammar file given\n", program_name);
  128.       exit(1);
  129.     }
  130.   if (optind < argc - 1)
  131.     fprintf(stderr, "%s: warning: extra arguments ignored\n", program_name);
  132.  
  133.   infile = argv[optind];
  134. }
  135.